In [21]:
import theano
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
import MDBN
In [22]:
import AML
me_DBN, ge_DBN, dm_DBN, top_DBN = AML.load_network('Exp_2016-12-11_1841_run_0.npz','../MDBN_run')
In [23]:
datafiles = AML.prepare_AML_TCGA_datafiles('../data')
In [24]:
ME_output, _ = me_DBN.MLP_output_from_datafile(datafiles['ME'], datadir='../data')
GE_output, _ = ge_DBN.MLP_output_from_datafile(datafiles['GE'], datadir='../data')
In [6]:
joint_layer = np.concatenate([ME_output, GE_output],axis=1)
plt.imshow(joint_layer, cmap='gray',interpolation='none')
plt.axis('tight')
Out[6]:
In [7]:
top_output = top_DBN.get_output(theano.shared(joint_layer,borrow=True))
plt.imshow((top_output>0.8)*np.ones_like(top_output)-(top_output<0.2)*np.ones_like(top_output),interpolation='none',extent=[0,3,385,0])
plt.colorbar()
plt.axis('tight')
plt.xticks(np.arange(0.5,3.5,1),('0','1','2'))
Out[7]:
In [8]:
plt.imshow(top_output, interpolation='none',extent=[0,3,385,0])
plt.axis('tight')
plt.colorbar()
plt.xticks(np.arange(0.5,3.5,1),('0','1','2'))
Out[8]:
In [9]:
plt.hist(top_output)
Out[9]:
In [10]:
plt.hist(top_output[:,0])
Out[10]:
In [11]:
code = (top_output[:,0:2] > 0.5) * np.ones_like(top_output[:,0:2])
In [12]:
from utils import find_unique_classes
U = find_unique_classes(code)
cl = U[0]
In [13]:
cl
Out[13]:
In [15]:
plt.hist(cl,bins=4)
Out[15]:
In [16]:
import csv
id=[]
with open('../data/'+datafiles['ME']) as f:
my_csv = csv.reader(f,delimiter='\t')
id = my_csv.next()
In [17]:
stat={}
with open('../data/AML/AML_clinical_data2.csv') as f:
reader = csv.reader(f, delimiter=',')
for row in reader:
patient_id=row[0]
stat[patient_id]=(row[4],row[7],row[6])
In [18]:
import re
time_list = []
event_list = []
group_list = []
print('The following case IDs were not found in clinical data')
for index, key in enumerate(id[1:]):
m = re.match('TCGA-\w+-\d+', key)
patient_id = m.group(0)
if patient_id in stat:
patient_stat = stat[patient_id]
add_group = True
try:
time_list.append(float(patient_stat[2]))
event_list.append(1)
except ValueError:
try:
time_list.append(float(patient_stat[1]))
event_list.append(0)
except ValueError:
print('No data for %s' % patient_id)
add_group = False
if add_group:
group_list.append(cl[index])
else:
print(patient_id)
In [19]:
from lifelines import KaplanMeierFitter
kmf = KaplanMeierFitter()
kmf.fit(time_list,event_observed=event_list)
kmf.plot()
Out[19]:
In [20]:
T=np.array(time_list)
E=np.array(event_list)
ix = (np.array(group_list) == 0)
kmf.fit(T[ix], E[ix], label='group 0')
ax=kmf.plot()
for i in range(1,4):
ix=(np.array(group_list)==i)
kmf.fit(T[ix], E[ix], label='group %d' % i)
kmf.plot(ax=ax)
In [ ]: